package com.example.su_shi_tan_home.child

import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.fastjson.JSON
import com.example.su_shi_tan_bas_lib.adapter.JssBaseViewHolder
import com.example.su_shi_tan_bas_lib.base.BaseFragmentEx
import com.example.su_shi_tan_bas_lib.base.SimpleListFragment
import com.example.su_shi_tan_bas_lib.bean.CommonBean
import com.example.su_shi_tan_bas_lib.networking.RestClient
import com.example.su_shi_tan_core.arouter.HomeARouter
import com.example.su_shi_tan_core.arouter.WalletARouterParams
import com.example.su_shi_tan_home.R
import com.example.su_shi_tan_home.bean.LightingTransBean
import ikidou.reflect.TypeBuilder
import java.lang.reflect.Type

/**
 *签到积分（转入）
 *
 * */
@Route(path = HomeARouter.LightingTransInFragment)
class LightingTransInFragment : SimpleListFragment<LightingTransBean>() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport = false

        isAddDividerItemDecoration = false
        isAlwaysRefresh = false

    }

    override fun initView(view: View) {
        super.initView(view)
        view.setBackgroundColor(Color.TRANSPARENT)
    }

    override fun getItemLayout(): Int {
        return R.layout.lighting_trans_in_fragment
    }

    override fun convertItem(helper: JssBaseViewHolder?, item: LightingTransBean?) {
        helper?.setText(R.id.from_addr, item?.from_addr)
            ?.setText(R.id.addTime, item?.add_time)
            ?.setText(R.id.numTv, item?.num)
    }

    override fun getListType(): Type = TypeBuilder.newInstance(CommonBean::class.java)
        .beginSubType(List::class.java)
        .addTypeParam(LightingTransBean::class.java).endSubType().build()

    override fun netRequest() {
        RestClient.builder()
            .url(R.string.user_transfer_list)
            .params("page", pageIndex)
            .params("limit", 10)
            .params("type", WalletARouterParams.LD)
            .params("transfer_type", "transfer_into")
            .success {

                parseDate(it)
            }.failure {
                onFailed()
            }.error { _, _ ->
                onFailed()
            }.build().get()
    }


    override fun parseDate(data: String?) {
//        super.parseDate(data)
        val mArray = JSON.parseArray(data, LightingTransBean::class.java)
        loadListDate(mArray)
    }

}